package com.bignerdranch.android.hellomoon;

//import android.net.Uri;
//import android.widget.VideoView;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class HelloMoonFragment extends Fragment {
	private Button mPlayButton;
	private Button mStopButton;
	private Button mPauseButton;
//	private VideoView videoView;

	private AudioPlayer mPlayer = new AudioPlayer();

	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setRetainInstance(true);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_hello_moon, container,
				false);
		mPlayButton = (Button) v.findViewById(R.id.hellomoon_playbutton);
		mStopButton = (Button) v.findViewById(R.id.hellomoon_stopbutton);
		mPauseButton = (Button) v.findViewById(R.id.hellomoon_pausebutton);
//		videoView = (VideoView) v.findViewById(R.id.VideoView);

		mPlayButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mPlayer.play(getActivity());

//				String uri = "android.resource://" + getActivity().getPackageName() 
//						+ "/" + R.raw.c;
//				videoView.setVideoURI(Uri.parse(uri));
//				videoView.start();
			}
		});
		mStopButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mPlayer.stop();
			}
		});
		mPauseButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mPlayer.pause()) {
					mPauseButton.setText(R.string.hellomoon_pause);
				} else {
					mPauseButton.setText(R.string.hellomoon_pause);
				}
			}
		});

		return v;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		mPlayer.stop();
	}

}
